/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bionic.socialNet.manager;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.NamingException;
import oracle.jdbc.pool.OracleDataSource;

/**
 *
 * @author Ann
 */
public class ConnectionPool {

    private final static String CACHE_NAME = "MYCACHE";
    OracleDataSource ods;
    Context ctx;
    private final String DATA_SOURCE = "scnet";

    public ConnectionPool() throws SQLException, NamingException {
        ods = new OracleDataSource();

        String mLogin = Config.getInstance().getProperty(Config.mainLogin);
        String mPass = Config.getInstance().getProperty(Config.mainPassword);

        ods.setDataSourceName(DATA_SOURCE);
        ods.setDriverType("thin");
        ods.setServerName("localhost"); // ?
        ods.setNetworkProtocol("tcp");
        ods.setDatabaseName("xe");
        ods.setPortNumber(1521);
        ods.setUser(mLogin);
        ods.setPassword(mPass);
        //String url = ods.getURL();

        Properties cacheProps = new Properties();
        cacheProps.setProperty("MinLimit", "1");
        cacheProps.setProperty("MaxLimit", "30");
        cacheProps.setProperty("InitialLimit", "1");
        ods.setConnectionCacheProperties(cacheProps);


    }

    public Connection getConnection() throws SQLException, NamingException {
        return ods.getConnection();
    }

    public void free(Connection conn) throws SQLException {
        if (conn != null) {
            conn.close();
        }

    }
}
